package com.hubu.tree;
/**
 * 兄弟表示法
 */
public class SibTree<T> extends AbstractTree<T> implements Tree<T>{
    public  Node<T> root;
    public SibTree(Printer<T> printer) {
        super(printer);
    }
    @Override
    public void afterAdd() {
    }
    @Override
    public void add(T value) {
    }
    @Override
    public void clear() {

    }

    @Override
    public void remove(T value) {

    }

    @Override
    public void preOrder() {

    }

    @Override
    public void midOrder() {

    }

    @Override
    public void postOrder() {
    }
    public static class Node<O>{
        Node<O> child;
        /**
         * 兄弟节点
         */
        public Node<O> sub;
        public O value;
        public Node(O value,Node<O> child,Node<O> sub){
            this.value=value;
            this.child=child;
            this.sub=sub;
        }
    }
    public void show(){
        if(null!=root){
            show(root);
        }
    }
    public void show(Node<T> node){
        //遍历当前节点
        if(node==null) return ;
        System.out.println(node.value);
        Node<T> current=node.sub;
        while(current!=null){
            System.out.println(current.value);
            if(current.child!=null){
                show(current.child);
            }
            current=current.sub;
        }
        //如果没有sub
        show(node.child);
    }
}
